package org.example.studentsdemo.course.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.example.studentsdemo.course.service.courseService;
import org.example.studentsdemo.student.entity.Students;
import org.example.studentsdemo.course.DTO.addStudentsToTeacherDTO;
import org.example.studentsdemo.course.entity.course;
import org.example.studentsdemo.course.mapper.courseMapper;
import org.example.studentsdemo.course.entity.course;
import org.example.studentsdemo.utils.HttpResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;

import java.util.*;
import java.util.function.Function;

@Service
public class courseServiceImpl implements courseService {

    @Autowired
    private courseMapper courseMapper;


    /**
     * @param entityList
     * @param batchSize
     * @return
     */
    @Override
    public boolean saveBatch(Collection<course> entityList, int batchSize) {
        return false;
    }

    /**
     * @param entityList
     * @param batchSize
     * @return
     */
    @Override
    public boolean saveOrUpdateBatch(Collection<course> entityList, int batchSize) {
        return false;
    }

    /**
     * @param entityList
     * @param batchSize
     * @return
     */
    @Override
    public boolean updateBatchById(Collection<course> entityList, int batchSize) {
        return false;
    }

    /**
     * @param entity
     * @return
     */
    @Override
    public boolean saveOrUpdate(course entity) {
        return false;
    }

    /**
     * @param queryWrapper
     * @param throwEx
     * @return
     */
    @Override
    public course getOne(Wrapper<course> queryWrapper, boolean throwEx) {
        return null;
    }

    /**
     * @param queryWrapper
     * @param throwEx
     * @return
     */
    @Override
    public Optional<course> getOneOpt(Wrapper<course> queryWrapper, boolean throwEx) {
        return Optional.empty();
    }

    /**
     * @param queryWrapper
     * @return
     */
    @Override
    public Map<String, Object> getMap(Wrapper<course> queryWrapper) {
        return Map.of();
    }

    /**
     * @param queryWrapper
     * @param mapper
     * @param <V>
     * @return
     */
    @Override
    public <V> V getObj(Wrapper<course> queryWrapper, Function<? super Object, V> mapper) {
        return null;
    }

    /**
     * @return
     */
    @Override
    public BaseMapper<course> getBaseMapper() {
        return null;
    }

    /**
     * @return
     */
    @Override
    public Class<course> getEntityClass() {
        return null;
    }

    /**
     * @return
     */
    @Override
    public ResponseEntity<HttpResult<List<course>>> getCourseList() {
        try {

            List<course> courseList = courseMapper.selectList(null);
            return new ResponseEntity<>(HttpResult.success(courseList), HttpStatus.OK);
        }catch (Exception e){
            e.printStackTrace();
            return  null;
        }
    }

    /**
     * @param id
     * @return
     */
    @Override
    public ResponseEntity<HttpResult<course>> getCourseById(Long id) {
        course course = courseMapper.selectById(id);

        return new ResponseEntity<>(HttpResult.success(course), HttpStatus.OK);
    }

    /**
     * @return
     */
    @Override
    public ResponseEntity<HttpResult<course>> addCourse(course Course) {
        courseMapper.insert(Course);
         return new ResponseEntity<>(HttpResult.success(Course), HttpStatus.OK);
    }

    /**
     * @return
     */
    @Override
    public ResponseEntity<HttpResult<course>> updateCourse(course Course) {
        courseMapper.updateById(Course);
       return new ResponseEntity<>(HttpResult.success(Course), HttpStatus.OK);
    }

    /**
     * @param id
     * @return
     */
    @Override
    public ResponseEntity<HttpResult<Boolean>> deleteCourse(Long id) {
      int coursetate  =   courseMapper.deleteById(id);
      if (coursetate > 0){
          return new ResponseEntity<>(HttpResult.success(true), HttpStatus.OK);
      }else{
          return new ResponseEntity<>(HttpResult.success(false), HttpStatus.OK);

      }

    }


}
